
#include "Vector.h"
using namespace std;
namespace common {

Vector::Vector() :
	x(0), y(0) {

}

Vector::Vector(skreal x, skreal y) {
	this->x = x;
	this->y = y;
}

Vector::Vector(const Vector & vector) {
	this->x = vector.getX();
	this->y = vector.getY();
}

skreal Vector::getX() const {
	return x;
}

skreal Vector::getY() const {
	return y;
}

void Vector::setX(skreal x) {
	this->x = x;
}

void Vector::setY(skreal y) {
	this->y = y;
}

skreal Vector::operator *(const Vector & vec) {
	return (this->getX() * vec.getX() + this->getY() * vec.getY());
}
Vector Vector::operator*(const skreal& d){
	return Vector(x*d,y*d);
}

Vector Vector::operator +(const Vector & vec) {
	return Vector(this->getX() + vec.getX(), this->getY() + vec.getY());
}

Vector Vector::operator -(const Vector & vec) {
	return Vector(this->getX() - vec.getX(), this->getY() - vec.getY());
}

skreal Vector::operator ^(const Vector & vec) {
	return (this->getX() * vec.getY() - this->getY() * vec.getX());
}

skreal Vector::length() const {
	return sqrt(x*x+y*y);
}
Vector Vector::unit(){
	if(length()>0){
		return Vector(x/length(),y/length());
	}
	return Vector();
}
std::string Vector::toString(void){
	std::stringstream os;
	os <<" v-[ " << getX() << ", " << getY() << "]";
	return os.str();
}
Vector::~Vector() {

}

std::istream& operator>>(std::istream& is, Vector &vec) {

	skreal x, y;
	is >> x;
	vec.setX(x);
	is >> y;
	vec.setY(y);
	return is;
}

ublasVector& operator<<(ublasVector& vec , const Vector& v){
	vec(0) = v.getX(); vec(1) = v.getY();
	return vec;
}

}
